#include <iostream>
#include <vector>
using namespace std;
int main()
{
    vector<string> a;
    int n;
    cin>>n;
    cin.ignore();
    for(int i = 0; i<n; i++)
    {
        string deal;
        getline(cin,deal);
      
        if(deal.find("in")==0)
        {
            a.push_back(deal.substr(3,deal.size()-3));
        }
       
        if(deal == "out")
        {
            if(!a.empty())
                a.erase(a.begin());
        }
        
        if(deal =="q")
        {
            if(a.empty())
                cout<<"NULL"<<endl;
            else
                cout<<a[0]<<endl;
        }
        
    }
}